package com.ty.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ty.mapper.PartnerMapper;
import com.ty.pojo.Partner;
import com.ty.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class PartnerServiceImpl implements PartnerService{
    @Autowired
    private PartnerMapper partnerMapper;

    @Override
    public PageResult getPartnerList(PageResult pageResult, Partner partner) {
        IPage<Partner> iPage = new Page<>(pageResult.getPageNum(), pageResult.getPageSize());
        QueryWrapper<Partner> queryWrapper = new QueryWrapper<>();
        boolean getName = StringUtils.hasLength(partner.getPartnerName());
        queryWrapper.and(Wrapper -> Wrapper.like(getName,"partner_name",partner.getPartnerName())
                .eq("state", 1));
        iPage = partnerMapper.selectPage(iPage, queryWrapper);
        List<Partner> records = iPage.getRecords();
        long total = iPage.getTotal();
        return pageResult.setTotal(total).setRows(records);
    }
}
